package com.itfallrain.controller;

import com.itfallrain.common.UserAuth;
import com.itfallrain.entity.User;
import com.itfallrain.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/main")
public class MainController {
    @Autowired
    private MainService mainService;
//    登录
    @RequestMapping("/menu")

    @ResponseBody
    public Object menu(HttpSession session) {
        User u = (User) session.getAttribute("login_id");
        Map<String, Object> map = new HashMap();
        map.put("userId", u.getId());
        map.put("userName", u.getName());
        List<Map<String, Object>> maps = mainService.selectAuthById(u.getId());
        map.put("menus", maps);
//        System.out.println(map);
        return map;
    }
//    安全退出
    @RequestMapping("/exit")
    @ResponseBody
    public void exit(HttpSession session) {
        session.removeAttribute("login_id");
    }


}
